<%-- 
    Document   : index
    Created on : 06/06/2011, 21:44:38
    Author     : fred
--%>

<%@page import="model.Pages"%>
<%@page import="model.User"%>

<%
    // Page being displayed
    String sOp = request.getParameter("op");
    if (sOp == null)
        sOp = Pages.HOME.toString();
    Pages op = Pages.valueOf(sOp.toUpperCase());

    // Logged user
    User user = null;
    Object obj = session.getAttribute("user");
    if (obj != null)
        user = (User) obj;
    
    // Message to be displayed
    String message = null;
    obj = session.getAttribute("message");
    if (obj != null)
        message = (String) obj;
%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css" type="text/css" media="all" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js" type="text/javascript"></script>
        
        <title>PCwitter<% if (user != null) { %> - Welcome <%= user.getName() %><% } %></title>
    </head>
    <body>
        <div id="wrap">
        
        <%---------------------------- Main bar ------------------------------%>
        
        <div class="supMenu">
            <div class="pageConf">
                <%------------------ Search div ------------------%>
                <div id="searchDiv">
                    <form action="index.jsp" action="GET">
                        <input type="hidden" value="<%= Pages.SEARCH %>" name="op" />
                        Search: <input type="text" name="search"
                                       maxlength="200"
                                       autocomplete="off"
                                       style="width: 200px" />
                        <input type="submit" value="Submit" style="width: 85px" />
                    </form>
                </div>

                <div style="float: right">
                    <%-------------- Login/Logout screen -------------%>
                    <% if (user == null) { %>
                    <form action="Login" method="POST">
                        <table cellspacing="3px" cellpadding="0" border="0">
                            <tr>
                                <td>Login:</td>
                                <td colspan="2">Password:</td>
                            </tr>
                            <tr>
                                <td><input type="text" name="login" style="width: 110px" /></td>
                                <td><input type="password" name="password" style="width: 110px" /></td>
                                <td><input type="submit" value="Login" style="width: 70px" /></td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <a href="index.jsp?op=<%= Pages.REGISTER %>"
                                       style="color: white">Register now</a>
                                </td>
                            </tr>
                        </table>
                    </form>
                    <% } else { %>
                    <p style="margin-top: 10px; width: 250px; text-align: right">
                        Hello <%= user.getName() %><br />
                        (<a href="Logout" style="color: white">Logout</a>)
                    </p>
                    <% } %>
                </div>
                
                <div style="float: left; margin-top: 10px;">
                    <ul id="listMenu">
                        <li><a href="index.jsp?op=<%= Pages.HOME %>">Home</a></li>
                        <li><a href="index.jsp?op=<%= Pages.USERS %>">Users</a></li>
                        <% if(user != null) { %>
                        <li><a href="index.jsp?op=<%= Pages.PROFILE %>">Profile</a></li>
                        <% } %>
                        <li><a href="index.jsp?op=<%= Pages.MOSTPOPULAR %>">Most popular users</a></li>
                    </ul>
                </div>
            </div>
        </div>
        
        <%--------------------------- Chosen page ----------------------------%>
        
        <div id="mainContent">
            <div class="pageConf">
                <%
                String mainPage = null;
                
                // Select page
                if (op == Pages.HOME) { %>
                    <% if (user == null) { %>
                    <div style="width: 400px; float: right">
                        <h1>Welcome to PCwitter</h1>
                        <h3>Create your account for free!</h3>
                        <hr />
                        <%@include file="WEB-INF/jspf/userCreate.jspf" %>
                    </div>
                    <% } else { %>
                    <%@include file="WEB-INF/jspf/mainScreen.jspf" %>
                    <% } %>
                <% } else if (op == Pages.USERS) { %>
                <%@include file="WEB-INF/jspf/users.jspf" %>
                <% } else if (op == Pages.SEARCH) { %>
                <%@include file="WEB-INF/jspf/search.jspf" %>
                <% } else if (op == Pages.MOSTPOPULAR) { %>
                <%@include file="WEB-INF/jspf/mostPopular.jspf" %>
                <% } else if (op == Pages.PROFILE) { %>
                <%@include file="WEB-INF/jspf/profile.jspf" %>
                <% } else if (op == Pages.FOLLOWERS) { %>
                <%@include file="WEB-INF/jspf/followers.jspf" %>
                <% } else if (op == Pages.FOLLOWEDS) { %>
                <%@include file="WEB-INF/jspf/followeds.jspf" %>
                <% } else if (op == Pages.EDITPROFILE) { %>
                <%@include file="WEB-INF/jspf/editProfile.jspf" %>
                <% } else if (op == Pages.EDITPASSWORD) { %>
                <%@include file="WEB-INF/jspf/editPassword.jspf" %>
                <% } else if (op == Pages.REGISTER) { %>
                <%@include file="WEB-INF/jspf/register.jspf" %>
                <% } else { %>
                <p>Page not found</p>
                <% } %>
            </div>
            
            <%--------------------------- Message ----------------------------%>
        
            <% if (message != null) { %>
            <div id="dialog-modal">
                <p>
                    <span class="ui-icon ui-icon-info" style="float:left; margin:0 7px 50px 0;"></span>
                    <%= message %>
                </p>
            </div>
            <script type="text/javascript">
                $("#dialog-modal").dialog({
                    height: 180,
                    modal: true,
                    buttons: {
                        Ok: function() {
                            $(this).dialog("close");
                        }
                    }
                });
            </script>
            <% } %>
        </div>
        
        </div>
        
        <%----------------------------- Footer -------------------------------%>
        
        <%@include file="WEB-INF/jspf/footer.jspf" %>
    </body>
</html>

<%
    session.setAttribute("message", null);
%>